#include <iostream>
#include <string>
#include <stdexcept>
#include "Sales_data.h"
using namespace std;
void practice_7_1();
void example_p231();
void practice_7_11();
void example_p258();
void test_const_obj();
/**int main()
{
	//practice_7_1();
	//example_p231();
	practice_7_11();
	//example_p258();
	return 0;
}

string Sales_data::isbn()
{
	string isbn;
	cin>>isbn;
	return isbn; 
}
Sales_data::Sales_data(istream &is)
{
	read(is,*this);
	print(cout,*this)<<endl;
}**/
Sales_data& Sales_data::combine(const Sales_data &chs)
{
	units_sold+=chs.units_sold;
	revenue+=chs.revenue;
	return *this;
}
istream &read(istream &is,Sales_data &item)
{
	double price=0;
	is>>item.bookNo>>item.units_sold>>price;
	item.revenue=price*item.units_sold;
	return is;
}
ostream &print(ostream &os,const Sales_data &item)
{
	os<<item.isbn()<<" "<<item.units_sold<<" "<<item.revenue<<" "<<item.avg_price();
	return os;
}
Sales_data add(const Sales_data &lhs,const Sales_data &rhs)
{
	Sales_data sum=lhs;
	sum.combine(rhs);
	return sum;
}
void practice_7_1()
{
	Sales_data total(cin);
	if(!total.isbn().empty()){
		istream &is=cin;
		while(is){
			Sales_data trans(is);
			if(total.isbn() == trans.isbn()){
				total.combine(trans);
			}
			else{
				print(cout,total)<<endl;
				total=trans;
			}
		}
		print(cout,total)<<endl;
	}
	else{
		throw std::runtime_error("input illegal");
	}
}
void example_p231()
{
	Sales_data s={};
	const Sales_data *s1=&s;
	cout<<s1->isbn();
}
void practice_7_11()
{
	string s("book1");
	string s1("book2");
	Sales_data sd(cin);
	Sales_data sd1(s);
	Sales_data sd2(s1,5,5.8);
	Sales_data sd3;
}
void example_p258()
{
	Sales_data s("zyl1",5,5.8);
	print(cout,s)<<endl;
}
void test_const_obj()
{
	const Sales_data s("ss");
}